import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../ly_weather.dart';

class LyWeatherWidget extends StatefulWidget {
  const LyWeatherWidget({Key? key}) : super(key: key);

  @override
  _DmWeatherWidgetState createState() => _DmWeatherWidgetState();
}

class _DmWeatherWidgetState extends State<LyWeatherWidget> {
  late WeatherUtils calculator;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    calculator =
        WeatherUtils.instance(appid: '81369875', appsecret: 'FkVSE6WF');

    calculator.getWeather().then((value) {
      if (mounted) setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Visibility(
        visible: calculator.weatherModel != null,
        child: Container(
          margin: EdgeInsets.symmetric(horizontal: 10.w),
          child: Row(
            children: [
              Image.asset(
                "assets/images/${calculator.weatherModel?.wea_img ?? ''}",
                width: 100.w,
                package: 'ly_weather',
              ),
              Expanded(
                  child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text(
                    'HI! ~ 今天${calculator.weatherModel?.wea}${calculator.weatherModel?.tem2}-${calculator.weatherModel?.tem1}℃',
                    style:
                        TextStyle(fontSize: 18.sp, fontWeight: FontWeight.w500),
                  ),
                  Text(
                    "${calculator.weatherModel?.air_tips}",
                    style:
                        TextStyle(fontSize: 18.sp, fontWeight: FontWeight.w500),
                  )
                ],
              ))
            ],
          ),
        ));
  }
}
